﻿using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;

namespace MainUI
{
    public static class IntPtrExtensions
    {
        public static IntPtr Increment( this IntPtr ptr, int cbSize )
        {
            return new IntPtr( ptr.ToInt64() + cbSize );
        }

        public static IntPtr Increment<T>( this IntPtr ptr )
        {
            return ptr.Increment( Marshal.SizeOf( typeof( T ) ) );
        }

        public static T ElementAt<T>( this IntPtr ptr, int index )
        {
            var offset = Marshal.SizeOf( typeof( T ) )*index;
            var offsetPtr = ptr.Increment( offset );
            return (T)Marshal.PtrToStructure( offsetPtr, typeof( T ) );
        }
    }
}
